new Vue({
  el: '#app',
  data() {
    return {
      select_list: [],
      form: {
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      formData: {},
      tableData: [{}],		//表格数据
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: [],
      Employees: [],
      treeProps: {
        label: 'label', // 对应节点的显示文本
        value: 'value', // 对应节点的值
        children: 'children' // 对应子节点的属性名
      },
      selectedData: [],
      giftcard: [],
    }
  },
  mounted() {
    this.getBuyer_Enterprise()
  },
  methods: {
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList({
        pageNow: this.form.page,
        pageSize: this.form.limit,
        Gift_Card_Scheme_Name: '',
        Enterprise_Info_SerialNumber: this.Enterprise_id,
      })
    },
    //号码按键查询
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList({
        pageNow: this.form.page,
        pageSize: this.form.limit,
        Gift_Card_Scheme_Name: '',
        Enterprise_Info_SerialNumber: this.Enterprise_id,
      })
    },
    handleCheckChange(e) {
      console.log('e', e)
      this.Enterprise_id = e.value;
      this.getList({
        pageNow: this.form.page,
        pageSize: this.form.limit,
        Gift_Card_Scheme_Name: '',
        Enterprise_Info_SerialNumber: this.Enterprise_id,
      })
    },
    getEmployees() {
      const this_ = this
      $.ajax({
        type: 'GET',
        url: `${BASE_URL}/User/getUserBelongEnterprise?enterpriseName=${$.cookie('enterprise') == '1' ? '' : decodeURI($.cookie('enterpriseName'))}`,
        success: function (res) {
          res = res.filter(item => item.Enterprise_Info_SerialNumber != '1')
          console.log('Employees', res)
          this_.Employees = res.map(item => {
            return {
              label: item.Enterprise_Name,
              value: item.Enterprise_Info_SerialNumber,
              children: item.Data.map(child => ({
                label: child.Nick,
                value: item.Enterprise_Info_SerialNumber,
                User_Number: child.Member_SerialNumber,
                roles: child.Role_List
              }))
            };
          });
        }
      })
    },
    getBuyer_Enterprise() {
      const this_ = this
      $.ajax({
        url: DomainName + '/getInquiryAction?token=' + $.cookie("token"),
        type: 'POST',
        data: {
          Data: 'enterprise_info',
          isNullEnterprise: true
        },
        success: function (res) {
          res = res.filter(item => item.Enterprise_Name != '系统管理')
          console.log('enterprise_info', res)
          this_.Employees = res.map(item => {
            return {
              label: item.Enterprise_Name,
              value: item.Enterprise_Info_SerialNumber,
            };
          });
        }
      })
    },
    getList(data) {//换页方法
      let _this = this
      $.ajax({
        type: 'GET',
        url: BASE_URL + '/GiftCard/getGiftCardList',
        data: data,
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          Result.data.data.forEach((item) => {
            item.Children = {}
          })
          _this.selectedData = Result.data.data
          console.log('Result', _this.selectedData);
          _this.total = Result.data.count;
        },
        dataType: "json"
      });
    },
    // 展开详细信息
    handleChildren(row, id = true) {
      console.log('展开详细信息', row)
      _this = this
      row.Children.article_specifications=[]
      $.ajax({
        url: BASE_URL + '/GiftCard/getCardInfo',
        type: 'GET',
        data: {
          pageNow: this.form.page,
          pageSize: this.form.limit,
          Gift_Card_Scheme_Name: row.Giftt_Card_Scheme_SerialNumber
        },
        success: function (res) {
          console.log('res.data.data', row, res)
          res.data.data.forEach((item, index) => {
            _this.$set(row.Children.article_specifications, index, item)
          })
        },
        dataType: "json"
      });

    },
    addEnterprise() {
      window.location.href = './Add.html'
    },
    showMember(EnterpriseInfo_SerialNumber) {
      sessionStorage.setItem("EnterpriseInfo_SerialNumber", EnterpriseInfo_SerialNumber)
      window.location.href = './show.html?EnterpriseInfo_SerialNumber=' + EnterpriseInfo_SerialNumber
    },
    editMember(EnterpriseInfo_SerialNumber) {
      sessionStorage.setItem("EnterpriseInfo_SerialNumber", EnterpriseInfo_SerialNumber)
      window.location.href = './Edit.html?EnterpriseInfo_SerialNumber=' + EnterpriseInfo_SerialNumber
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  },
})